<?php

namespace App\Trip\Enums\Plane;

use Exception;

enum PlaneChangeTypes: int
{
    //航班可选改签类型 1 申请改期 姓名必填 , 2 改名 4 改证件号 (填写需要变更的证件号),8 航变改期 16 其他变更备注comment填写变更要求
    case CHANGE_DATE          = 1;
    case CHANGE_TRUENAME      = 2;
    case CHANGE_IDENTITY_CODE = 4;
    case FLIGHT_CHANGE_DATE   = 8;
    case CHANGE_OTHER         = 16;


    public static function defaultType(): int
    {
        return self::default()->value;
    }

    public static function default(): PlaneRefundTypes
    {
        return PlaneRefundTypes::REFUND_TYPE_VOLUNTARILY;
    }

    /**
     * @throws Exception
     */
    public function detail(): array
    {
        return match ($this) {
            self::CHANGE_DATE, self::FLIGHT_CHANGE_DATE                           => [
                "reason"    => $this->getReason(),
                "reason_uy" => $this->getReasonUy(),
                "is_show"   => 1,
            ],
            self::CHANGE_TRUENAME, self::CHANGE_OTHER, self::CHANGE_IDENTITY_CODE => throw new Exception('To be implemented'),
        };
    }

    public function getReason(): string
    {
        return match ($this) {
            self::CHANGE_DATE          => "改期",
            self::CHANGE_TRUENAME      => "变更姓名",
            self::CHANGE_IDENTITY_CODE => "该证件号",
            self::FLIGHT_CHANGE_DATE   => "航变改期",
            self::CHANGE_OTHER         => "其他变更",
        };
    }

    /**
     * @throws Exception
     */
    public function getReasonUy(): string
    {
        return trans2uy($this->getReason());
    }

}